<#assign pageName="系统角色管理">
<@override name="page-content">
    <form class="layui-form form-horizontal" role="form" method="post">
        <div class="layui-form-search panel">
            <input type="text" hidden="hidden" name="_STATE"/>
            <@ctrl.TreeSelectQuery path="roles.guid" dataList=guidsList![] fieldText="sysModuleName"
                fieldValue="guid" labelText="所属平台" fieldParentID="upperGuid" parentidValue="${(guids.upperGuid)!'-1'}" />
            <@ctrl.TreeSelectQuery path="roles.depId" dataList=depList![] class="" fieldText="depName"  labelText="所属机构"
                fieldValue="depId" fieldParentID="upperId" parentidValue="${(dep.upperId)!'-1'}">
                <option value="">—请选择所属机构—</option>  
            </@ctrl.TreeSelectQuery>
            <div class="margin-5">
                <a href="javascript:;" onclick="$('#pageNo').val(1);$('form:first').submit();" class="layui-btn layui-btn-sm">
                    <i class="layui-icon layui-icon-search"></i>查询
                </a>
                <a href="javascript:;" class="layui-btn layui-btn-warm layui-btn-sm js-reset">
                    <i class="layui-icon layui-icon-refresh-1"></i>重置
                </a>
                <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-sm js-add">
                    <i class="layui-icon layui-icon-add-1"></i>新增
                </a>
                <a href="javascript:;"  class="layui-btn layui-btn-danger layui-btn-sm" onclick="confirmSubmit('确定要重载资源吗？', {},'${contextPath}/admin/reloadresources')">
                    <i class="layui-icon layui-icon-refresh"></i>资源重载
                </a>
            </div>
        </div>
        <table class="layui-table">
            <thead>
                <tr>
                    <th class="align-center" width="50px" nowrap="nowrap">序号</th>
                    <th class="align-center layui-hide-xs" nowrap="nowrap">所属机构</th>
                    <th class="align-center" nowrap="nowrap">内置角色</th>
                    <th class="align-center" nowrap="nowrap">角色编码</th>
                    <th class="align-center" nowrap="nowrap">角色名称</th>
                    <th class="align-center layui-hide-xs">角色描述</th>
                    <th class="align-center" nowrap="nowrap">状态</th>
                    <th width="100px" class="align-center">操作</th>
                </tr>
            </thead>
    
            <tbody>
            <#if (queryResult.rows)?has_content>
                <#list queryResult.rows as dataItem>  
                <tr>
                    <td class="align-center" width="50px" nowrap="nowrap">
                        ${(pageNo-1)*pageSize+dataItem_index+1}
                    </td>
                    <td class="align-center layui-hide-xs" nowrap="nowrap">
                        <span title="${dataItem.dep_id}">
                            ${findItem(depList,'depId','${dataItem.depId}').depName}
                        </span>
                    </td>
                    <td class="align-center" nowrap="nowrap">
                        <#if dataItem.buildIn?string == "0">
                            <span>非内置</span>
                        <#else>
                            <span>内置</span>
                        </#if>
                    </td>
                    <td class="align-center" nowrap="nowrap">
                        ${dataItem.roleCode}
                    </td>
                    <td nowrap="nowrap" class="align-center">
                        ${dataItem.roleName}
                    </td>
                    <td class="layui-hide-xs" >
                        <span title="${dataItem.memo}">${dataItem.memo}</span>
                    </td>
                    <td class="align-center" nowrap="nowrap">
                        <#if dataItem.enable?string == "T">
                            <span class="layui-bg-green status-show">启用</span>
                        <#else>
                            <span class="layui-bg-red status-show">禁用</span>
                        </#if>
                    </td>
                    <td class="align-center">
                        <div class="layui-table-cell">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" href="edit/${dataItem.roleId}">
                                <i class="layui-icon layui-icon-edit"></i>编辑
                             </a> 
                             <button type="button" class="layui-btn layui-btn-danger layui-btn-xs"
                                onclick="confirmSubmit('确定要删除角色‘${dataItem.roleName}’吗？', {roleId:'${dataItem.roleId}'},'del')">
                                <i class="layui-icon layui-icon-delete"></i>删除
                             </button>
                        </div>
                    </td>
                </tr>
                </#list>
            <#else>
                <tr>
                    <td colspan="8" style="color:red;text-align:center;font-weight:bold;">暂无符合条件的角色信息</td>
                </tr>
            </#if>
            </tbody>
        </table>
        <@ctrl.pageShow (queryResult.total)!0, (queryResult.pageIndex)!0 />
    </form>
</@override>
<@override name="page-scripts">
    <script>
        $(function(){
            layui.use(['form','layer', 'jquery'], function(){
                var form=layui.form;
                var layer=layui.layer;
                var $ = layui.jquery;
                $('.js-add').on('click', function(){
                    var guid = $('#guid').val();
                    window.location.href="${contextPath}/admin/roles/add/"+guid;
                });
                $('.js-reset').on('click', function(){
                    $('#pageNo').val(1);
                    $('#depId').val("");
                    $('form:first').submit();
                });
                //平台机构联动
               form.on('select(guid)', function(data){
                   var guid = data.value;
                   $.post('${rc.getContextPath()}/admin/department/queryall', {'guid': guid}, function(data){
                       var $html = "<option value=''>－请选择所属机构－</option>"
                       $.each(data, function(index, item){
                           $html += "<option value='" + item.depId + "'>" + item.depName + "</option>";
                       })
                       $("#depId").html($html);
                       form.render("select");
                   })
               });
            })
        })
    </script>
</@override>
<@extends name="/layout/basepage.html"/> 